import 'package:lishopflu/base/base_import.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/global/app_color.dart';
/*
  可以共用的widget等
 */
class CommonWidget {

  /*
    顶部左上角返回键
   */
  static Widget leading(GestureTapCallback ontap){
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      child: Icon(Icons.arrow_back, color: Colors.white,),
      onTap: ontap,
    );
  }

  /*
    分割线
   */
  static Widget divide({Color color, double height}){
    return Divider(
      color: color==null?AppColor.divider:color,
      height: height==null?1:height,
    );
  }

  /*
    ICon 默认向右箭头
   */
  static Widget icon({IconData icon, Color color}){
    return Icon(
        icon==null?Icons.chevron_right:icon,
        color: color==null?AppColor.divider:color
    );
  }

  /*
    背景边框
   */
  static Decoration boxWhite({double radius, Color bg}){
    return BoxDecoration(
      color: bg==null?Colors.white:bg,
      borderRadius: BorderRadius.circular(radius==null?10:radius),
      boxShadow: [
        BoxShadow(
          color: Color(0xFFECECEC),  //底色,阴影颜色
          blurRadius: 5,  // 阴影模糊层度
          spreadRadius: 0.2,  //阴影模糊大小
        ),
      ],
    );
  }

  /*
    渐变背景
   */
  static Decoration boxColor({double radius, List<Color> bg}){
    return BoxDecoration(
      borderRadius: BorderRadius.circular(radius==null?10:radius),
      gradient: LinearGradient(
          colors: bg==null?[Colors.orangeAccent, Colors.orange, Colors.deepOrange]:bg
      ),
    );
  }

  /*
    透明边框，解决TextField不居中问题
   */
  static OutlineInputBorder inputCenter(){
    return OutlineInputBorder(
      borderSide: BorderSide(
        color: Colors.transparent,
      ),
    );
  }

  /*
    背景边框
   */
  static Widget labelEdit(String label, TextEditingController controller, {String hintText, TextInputType inputType, int maxLines, bool readOnly}){
    return Row(
      children: [
        Text(label, style: TextStyle(color: AppColor.c333333),),
        Expanded(
          flex: 1,
          child: TextField(
            decoration: InputDecoration(
//              labelText: hintText==null?"":hintText,
              hintText: StringUtil.isEmpty(hintText)?"":hintText,
              prefixIcon: null,
              border: inputCenter(),
              enabledBorder: inputCenter(),
              disabledBorder: inputCenter(),
              focusedBorder: inputCenter(),
              contentPadding: EdgeInsets.only(left: 10, right: 10),
              hintStyle: TextStyle(color: AppColor.c979797, fontSize: 14),
            ),
            keyboardType: inputType==null?TextInputType.multiline:inputType,
            controller: controller,
            style: TextStyle(color: AppColor.c505050, ),
            maxLines: maxLines==null?5:maxLines,
            minLines: 1,
            readOnly: readOnly==null ? false : readOnly,
          ),
        ),
      ],
    );
  }

  /*
    点击选择
   */
  static Widget tapText(String label, String str, GestureTapCallback ontap, {String hintText, int maxLines, Color bgColor, bool showIcon}){
    if(hintText==null)
      hintText = '';
    return InkWell(
      child: Container(
        color: bgColor==null?AppColor.transparent:bgColor,
        padding: EdgeInsets.only(top: 10, bottom: 10),
        child: Row(
          children: [
            Text(label, style: TextStyle(color: AppColor.c333333),),
            Spacer(),
            Padding(
              padding: EdgeInsets.only(left: 10, right: 10),
              child: Text(
                StringUtil.isEmpty(str)?hintText:str,
                overflow: TextOverflow.ellipsis,
                maxLines: maxLines==null?1:maxLines,
                style: TextStyle(
                    color: StringUtil.isEmpty(str)?AppColor.c979797:AppColor.c505050,
                ),
              ),
            ),
            showIcon!=null&&showIcon==false?Padding(padding: EdgeInsets.zero):icon(),
          ],
        ),
      ),
      onTap: ontap,
    );
  }

}
